import request from '@/config/axios'

// 金料调拨相关 API 定义
export interface TransferPageReq {
  pageNo: number
  pageSize: number
  transferNo?: string
  transferType?: number | null
  status?: number | null
}

export interface TransferRespVO {
  id: number
  transferNo: string
  transferType: number
  fromWarehouseId: number
  toWarehouseId: number
  transferWeight: number
  transferReason?: string
  status: number
  approverId?: number
  approveTime?: string
  approveRemark?: string
  attachmentUrl?: string
  createTime: string
  updateTime: string
  fromWarehouseName?: string
  toWarehouseName?: string
  approverName?: string
  creatorName?: string
}

export interface TransferApproveReq {
  id: number
  decision: number // 1-通过 2-拒绝
  approveRemark?: string
}

// 分页查询调拨记录
export const getTransferPage = (params: TransferPageReq) => {
  return request.get({ url: '/gold/material/transfer/page', params })
}

// 获取调拨详情
export const getTransfer = (id: number) => {
  return request.get({ url: `/gold/material/transfer/${id}` })
}

// 审批调拨单
export const approveTransfer = (data: TransferApproveReq) => {
  return request.put({ url: '/gold/material/transfer/approve', data })
}

// 查询待审核的调拨单
export const getPendingApprovals = () => {
  return request.get({ url: '/gold/material/transfer/pending' })
}

// 查询指定仓库的调拨记录
export const getTransfersByWarehouseId = (warehouseId: number) => {
  return request.get({ url: `/gold/material/transfer/warehouse/${warehouseId}` })
}
